//
// Created by 高炎 on 2024/7/28.
// 实现的是升序排序
//
#include <iostream>
#include <vector>
using namespace std;

void SelectSort(vector<int>& arr)
{
    for (int i = 0; i < arr.size() - 1; i++)
    {
        int min = i;
        for (int j = i + 1; j < arr.size(); j++)
        {
            if (arr[min] > arr[j])
            {
                min = j;
            }
        }
        if (min != i)
        {
            // 此时交换
            int temp = arr[i];
            arr[i] = arr[min];
            arr[min] = temp;
        }
    }
    // 输出数组
    // for (int i = 0; i < arr.size(); i++)
    // {
    //     cout << arr[i] << ",";
    // }
    // cout << endl;
}

int main()
{
    vector<int> arr = {4, 3, 99, 7, 9};
    for (int i = 0; i < arr.size(); i++)
    {
        cout << arr[i] << ",";
    }
    cout << endl;
    SelectSort(arr);
    for (int i = 0; i < arr.size(); i++)
    {
        cout << arr[i] << ",";
    }

    return 0;
}